
/*
 * A sample program demonstrating usage of boost::any
 * Author: Ganesh M <ganesh.muniyandi@gmail.com>
 * Date: 10/27/2010
 */


#include <iostream>
#include <stdio.h>
#include <boost/any.hpp>

int main() {
    int number = 30; 
    std::string str = "Hello World";
    boost::any a1 = number; 
    boost::any a2 = str; 

    try { 
         if( a1.type() == typeid(int) ) 
         {
             number = boost::any_cast<int>(a1); 
             printf("%d\n", number);
         }
         if( a2.type() == typeid(std::string) ) 
         {
             str = boost::any_cast<std::string>(a2); 
             printf("%s\n", str.c_str());
         }
    } 
    catch(boost::bad_any_cast& e) 
    { 
        std::cout << "Bad any cast!\n"; 
    } 

    return 0;
}
